package phase3_testCase;

import static org.junit.Assert.*;

import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.util.Vector;

import org.junit.Test;

import phase3.Dictionary;

public class Dictionary_testCase {

	@Test
	public void testDictionary1() {
		Dictionary d1 = new Dictionary();
		assertEquals(0, d1.getIndex());
	}
	
	@Test
	public void testDictionary2() {
		Dictionary d1 = new Dictionary('a');
		assertEquals('a', d1.getIndex());
	}
	
	@Test
	public void testGetNumOfWords() {
		Dictionary d1 = new Dictionary('c');
		assertEquals(23, d1.getNumOfWords());
	}
	
	@Test
	//test 'a' at SetIndex
	public void testSetIndex1() {
		Dictionary d1 = new Dictionary();
		d1.setIndex('a');
		assertEquals('a', d1.getIndex());
	}
	
	@Test
	//test '2' at SetIndex
	public void testSetIndex2() {
		Dictionary d1 = new Dictionary();
		d1.setIndex('2');
		assertEquals(0, d1.getIndex());
	}
	
	@Test
	//test 'C' at SetIndex
	public void testSetIndex3() {
		Dictionary d1 = new Dictionary();
		d1.setIndex('}');
		assertEquals(0, d1.getIndex());
	}

	//test with 'a'
	@Test
	public void testGetAll1(){
		boolean result = false;
		Dictionary d1 = new Dictionary();
		d1.setIndex('a');
		Vector<String> temp = new Vector<String>();
		temp = d1.getAll();
		
		for(int i = 0; i < temp.size(); i++){
			if(temp.get(i).charAt(0) == 'a')
				result = true;
			else{
				result = false; 
				break;
			}
		}			
		assertEquals(true, result);
	}
	
	//test with 'f'
	@Test
	public void testGetAll2(){
		boolean result = true;
		Dictionary d1 = new Dictionary();
		d1.setIndex('f');
		Vector<String> temp = new Vector<String>();
		temp = d1.getAll();
		
		for(int i = 0; i < temp.size(); i++){
			if(temp.get(i).charAt(0) == 'f')
				result = true;
			else{
				result = false; 
				break;
			}
		}			
		assertEquals(true, result);
	}
	
	//test with 'y'
	@Test
	public void testGetAll3(){
		boolean result = false;
		Dictionary d1 = new Dictionary();
		d1.setIndex('y');
		Vector<String> temp = new Vector<String>();
		temp = d1.getAll();
		
		for(int i = 0; i < temp.size(); i++){
			if(temp.get(i).charAt(0) == 'f')
				result = true;
			else{
				result = false; 
				break;
			}
		}			
		assertEquals(false, result);
	}

	@Test
	//test all valid input
	public void testGetMaxLength1() {
		Dictionary d1 = new Dictionary();
		int tempLimit = d1.getMaxLength('a', 'b', 'c');
		assertEquals(tempLimit, 12);
	}
	
	@Test
	//test only two valid input
	public void testGetMaxLength2() {
		Dictionary d1 = new Dictionary();
		int tempLimit = d1.getMaxLength(' ', 'f', 'h');
		assertEquals(tempLimit, 12);
	}
	
	@Test
	//test only 1 valid input
	public void testGetMaxLength3() {
		Dictionary d1 = new Dictionary();
		int tempLimit = d1.getMaxLength(' ', ' ', 'z');
		assertEquals(tempLimit, 12);
	}
	
	@Test
	//test only 1 valid input 
	public void testGetMaxLength4() {
		Dictionary d1 = new Dictionary();
		int tempLimit = d1.getMaxLength(' ', 'r', ' ');
		assertEquals(tempLimit, 12);
	}
	
	@Test
	//test only 1 valid input
	public void testGetMaxLength5() {
		Dictionary d1 = new Dictionary();
		int tempLimit = d1.getMaxLength('a', 'b', 'c');
		assertEquals(tempLimit, 12);
	}
	
	@Test
	//test input char a
	public void testGetMaxLength6() {
		Dictionary d1 = new Dictionary();
		int tempLimit = d1.getMaxLength('a', 'b', 'c');
		assertEquals(tempLimit, 12);
	}
	
	@Test
	//test input char a
	public void testGetMaxLength7() {
		Dictionary d1 = new Dictionary();
		int tempLimit = d1.getMaxLength('a', 'b', 'c');
		assertEquals(tempLimit, 12);
	}
	
	@Test
	//test input char a
	public void testGetMaxLength8() {
		Dictionary d1 = new Dictionary();
		int tempLimit = d1.getMaxLength('a', 'b', 'c');
		assertEquals(tempLimit, 12);
	}
	
	@Test
	//test string 'aba'
	public void testCheck1() {
		Dictionary d1 = new Dictionary();
		d1.setIndex('a');
		boolean result = d1.check("aba");
		assertEquals(true, result);
	}

	@Test
	//test string 'girl'
	public void testCheck2() {
		Dictionary d1 = new Dictionary();
		d1.setIndex('g');
		boolean result = d1.check("girl");
		assertEquals(false, result);
	}
	
	@Test
	//test string ' '
	public void testCheck3() {
		Dictionary d1 = new Dictionary();
		d1.setIndex('m');
		boolean result = d1.check(" ");
		assertEquals(false, result);	
	}
	@Test
	//test input char a
	public void testGetMaxLengthStub1() {

        class DictionaryStub extends Dictionary{
            @Override
            public Vector<String> getAll()
            { 
            	Vector<String> tempVector = new Vector<String>();
            	String temp="apple";
            	tempVector.add(temp);
                return tempVector;
            }
    	
        };
    	DictionaryStub d1 = new DictionaryStub();
    	int tempLimit = d1.getMaxLength('a', 'b', 'c');
		assertEquals(tempLimit, 5);
	}
	@Test
	//test input char a
	public void testGetMaxLengthStub2() {

        class DictionaryStub extends Dictionary{
            @Override
            public Vector<String> getAll()
            { 
            	Vector<String> tempVector = new Vector<String>();
            	String temp="zzaa";
            	tempVector.add(temp);
                return tempVector;
            }
    	
        };
    	DictionaryStub d1 = new DictionaryStub();
    	int tempLimit = d1.getMaxLength(' ', ' ', 'z');
		assertEquals(tempLimit, 4);
	}
	@Test
	//test input char a
	public void testGetMaxLengthStub3() {

        class DictionaryStub extends Dictionary{
            @Override
            public Vector<String> getAll()
            { 
            	Vector<String> tempVector = new Vector<String>();
            	String temp="ffffff";
            	String temp2="hh";
            	tempVector.add(temp);
            	tempVector.add(temp2);
                return tempVector;
            }
    	
        };
    	DictionaryStub d1 = new DictionaryStub();
    	int tempLimit = d1.getMaxLength(' ', 'f', 'h');
		assertEquals(tempLimit, 6);
	}
	@Test
	//test input char a
	public void testGetMaxLengthStub4() {

        class DictionaryStub extends Dictionary{
            @Override
            public Vector<String> getAll()
            { 
            	Vector<String> tempVector = new Vector<String>();
            	String temp="rubber";
            	tempVector.add(temp);
                return tempVector;
            }
    	
        };
    	DictionaryStub d1 = new DictionaryStub();
    	int tempLimit = d1.getMaxLength(' ', ' ', 'r');
		assertEquals(tempLimit, 6);
	}

	@Test
	//test input with no char (for loop test)
	public void testGetMaxLength9() {
		Dictionary d1 = new Dictionary();
		int tempLimit = d1.getMaxLength(' ', ' ', ' ');
		assertEquals(tempLimit, 0);
	}
	
}
